/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    int maxdepth = 0;
    public int maxDepth(TreeNode root) {
        if(null == root) {
            return 0;
        }
        inorder(root,1);
        return maxdepth;
    }
    private void inorder(TreeNode root,int depth) {
        if(null == root) {
            return;
        }
        maxdepth = Math.max(depth,maxdepth);
        inorder(root.left,depth+1);
        inorder(root.right,depth+1);
    }
}